<template>
	<view style="height: 100vh;width: 100%;background-color: white;">
		<view style="margin: 20rpx 20rpx 10rpx 20rpx;background-color: white;">
			<view style="width: 100%;height: 10rpx;background-color: #FFFFFF;"></view>
			<view style="font-size: 28rpx;font-weight: 600;margin-top: 20rpx;">
				{{listData.title}}
			</view>
			<view style="color: #6D6D6D;font-size: 24rpx;margin-top: 10rpx;white-space: pre-line;"
				v-html="listData.message">
			</view>
		</view>
		<view style="width: 100%;height: 20rpx;background-color: #F8F8F8;"></view>
		<view style="background-color: white;height: 40rpx;width: 100%;padding-left: 20rpx;line-height: 40rpx;">
			全部动态
		</view>
		<dynamic ref="dynamic" :bootId="bootId" :userId="userId" :token="token" @dsFun="dsFun">
		</dynamic>
		<view v-show="showBtn == true">


			<view v-if="listData.type == '课程'">
				<button type="primary"
					:style="listData.daka == 0 ? 'background-color: #ea5550' : 'background-color: rgb(163,173,179)' "
					class="call" @click="toCall()">{{listData.daka == 0 ? '去打卡' : '已打卡'}}</button>
			</view>


			<view v-else>
				<button type="primary" class="call" :disabled="listData.join == 1 ? true:false "
					:style="listData.join == 1 ? 'background-color: rgb(163,173,179)' : 'background-color: #ea5550' "
					@click="toCall()">{{listData.join == 0 ? '预约直播：' + listData.plan_date : '已预约'}}</button>
			</view>
		</view>

	</view>
</template>

<script>
	import animationType from '@/utils/animationType.js'
	import {
		getBootcampHomework,
		addBootcampZhiBoYuYue
	} from '@/api/camp.js';
	import dynamic from '../../workshop/components/dynamic.vue';
	export default {
		components: {
			dynamic
		},
		props: {
			bootId: {
				type: String,
				required: true,
				default: ''
			},
			userId: {
				type: String,
				required: true,
				default: ''
			},
			token: {
				type: String,
				required: true,
				default: ''
			},
			dyTitle: {
				type: String,
				required: true,
				default: ''
			},
			hwId: {
				type: String,
				required: true,
				default: ''
			},
		},
		data() {
			return {
				listData: {},
				showBtn: true,
				open_date: '',
			}
		},
		mounted() {
			let that = this;
			that.getList();
			console.log('￥￥￥@@@&&&&  ----' + that.getNowFormatDate())
		},
		created() {
			uni.$on('refreshCommentList', this.refreshList);
		},
		beforeDestroy() {
			uni.$off('refreshCommentList'); // 避免内存泄漏
		},
		methods: {
			//获取当前日期函数
			getNowFormatDate() {
				let date = new Date(),
					year = date.getFullYear(), //获取完整的年份(4位)
					month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
					strDate = date.getDate(); // 获取当前日(1-31)
				if (month < 10) month = `0${month}`; // 如果月份是个位数，在前面补0
				if (strDate < 10) strDate = `0${strDate}`; // 如果日是个位数，在前面补0

				return `${year}-${month}-${strDate}`;
			},

			bottomGet() {
				let that = this;
				that.$refs.dynamic.bottomRequest();
			},
			refreshList() {
				let that = this;
				console.log('@@@&&&&  ----')
				that.getList();
			},
			dsFun(e) {
				console.log('666===!!!!');
				let that = this;
				if (e == true) {
					that.showBtn = false;
				} else {
					that.showBtn = true;
				}
			},
			getList() {
				let that = this;
				let p = {};
				p.userId = that.userId;
				p.token = that.token;
				p.id = that.hwId;
				getBootcampHomework(p).then(res => {
					if (res.code == 0) {
						that.listData = {};
						that.listData = res.data;
					}
				})
			},
			toCall() {
				let that = this;
				if (that.listData.type == '课程') {
					if (that.listData.open_date <= that.getNowFormatDate()) {
						uni.navigateTo({
							animationType: animationType.type,
							animationDuration: animationType.duration,
							url: '/pages/dailystudy/signin?bootId=' + that.bootId + '&userId=' + that.userId +
								'&token=' + that.token + '&dyTitle=' + that.dyTitle + '&arrangeId=' + that.hwId,
						})
					} else {
						uni.showToast({
							title: "当天的课程当天才能打卡",
							icon: 'none'
						})
						// uni.navigateTo({
						// 	animationType: animationType.type,
						// 	animationDuration: animationType.duration,
						// 	url: '/pages/dailystudy/signin?bootId=' + that.bootId + '&userId=' + that.userId +
						// 		'&token=' + that.token + '&dyTitle=' + that.dyTitle + '&arrangeId=' + that.hwId,
						// })
					}

				} else {
					//预约直播
					if (that.listData.join == 1) {
						return;
					}
					let p = {};
					p.userId = that.userId;
					p.token = that.token;
					p.planId = that.listData.jump_id;
					addBootcampZhiBoYuYue(p).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: "预约成功"
							})
							that.getList();
						}
					})
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.call {
		position: fixed;
		bottom: 60rpx;
		left: 40rpx;
		background-color: #ea5550;
		font-size: 30rpx;
		width: calc(100% - 80rpx);
		height: 80rpx;
		line-height: 80rpx;
	}
</style>